package cn.senjoeson.triper.utils;

import android.content.Context;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;

/**
 * Created by senjoeson on 2018/2/4.
 */

public class ReadAssetFileUtils {

    public static String readFile(Context context, String fileName) {
        try {
            InputStream inputStream = context.getClass().getClassLoader().getResourceAsStream("assets/" + fileName);
            StringBuilder stringBuilder = new StringBuilder();
            String sTempOneLine =null;
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(inputStream));
            while ((sTempOneLine = bufferedReader.readLine()) != null) {
                stringBuilder.append(sTempOneLine);
            }
            inputStream.close();
            bufferedReader.close();
            return stringBuilder.toString();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }
}
